package com.zhytech.controller;

import com.zhytech.beans.Quote;
import com.zhytech.service.RestClient;
import com.zhytech.beans.Greeting;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicLong;

/**
 * Created by zhy on 2017/3/17.
 */

@RestController
public class mainController {

    private static final Logger log = LoggerFactory.getLogger(mainController.class);
    private static final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();

    @Autowired
    RestClient restClient;

    @RequestMapping("/greeting")
    public Greeting greeting(@RequestParam(value="name",defaultValue = "ZHY") String name){
        return new Greeting(counter.incrementAndGet(),
                                String.format(template,name));
    }

    @RequestMapping("SpringAPI")
    public Quote getSpringQuote(){
        log.info("------------ Get Request -------");
        return restClient.getQuote();
    }



}
